<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<div id="required_fields_message">Fields in red are required</div>
<ul id="error_message_box"></ul>
<form action="<s:url action="update"/>" method="post" accept-charset="utf-8" id="item_form">
<fieldset id="item_basic_info">
<legend>Payment Information</legend>

 <jsp:useBean id="dateValue" class="java.util.Date" />

<div class="field_row clearfix">
<label for="customerId" class="required wide">Customer Name:</label>	<div class='form_field'>
	<input type="text" id="name" name="customerId" value="${paymentEntity.customer.name}" id="name"  />	</div>
</div>

<div class="field_row clearfix">
<label for="paymentType" class="required wide">Payment Type:</label>
<div class='form_field'>
	<select name="paymentType">
           <option value="1" selected="selected" >Cash</option>
           <option value="2"  >Check</option>
             <option value="3"  >Bank Transfer</option>
        </select>
     </div>
</div>

<div class="field_row clearfix">
<label for="paymentAmount" class="required wide">Payment Amount:</label>
<div class='form_field'>
	<input type="text" name="paymentAmount" value="${paymentEntity.customer.name}" id="paymentAmount"  />	</div>
</div>
  <jsp:setProperty name="dateValue" property="time" value="${paymentEntity.paymentDate}" />

<div class="field_row clearfix">
<label for="paymentDate" class=" wide">Payment Amount:</label>	<div class='form_field'>
	<input type="text" name="paymentDate" value="${dateValue}" id="name"  />	</div>
</div>
<div class="field_row clearfix">
<label for="description" class="wide">Comment:</label>
	<div class='form_field'>
	<textarea name="comment" cols="17" rows="5" id="description" >${paymentEntity.note}</textarea>
	</div>
</div>


<input type="submit" name="submit" value="Submit" id="submit" class="submit_button float_right"  /></fieldset>
</form><script type='text/javascript'>

//validation and submit handling
$(document).ready(function()
{
	$( "#name" ).autocomplete({
		source: "${pageContext.request.contextPath}/customers/search.ps",
		delay: 10,
		autoFocus: false,
		minLength: 0
	});

	var submitting = false;

	$('#item_form').validate({
		submitHandler:function(form)
		{
			if (submitting) return;
			submitting = true;
			$(form).mask("Please wait...");
			$(form).ajaxSubmit({
			success:function(response)
			{
				submitting = false;
				tb_remove();
				post_item_form_submit(response);
			},
			dataType:'json'
		});

		},
		errorLabelContainer: "#error_message_box",
 		wrapper: "li",
		rules:
		{
			customerId:"required",
			paymentType:"required",
			paymentAmount:
			{
				required:true,
				number:true
			},

			unit_price:
			{
				required:true,
				number:true
			},
			tax_percent:
			{
				required:true,
				number:true
			},
			quantity:
			{
				required:true,
				number:true
			},
			reorder_level:
			{
				required:true,
				number:true
			}
   		},
		messages:
		{
			name:"Item Name is a required field",
			category:"Category is a required field",
			cost_price:
			{
				required:"Cost Price is a required field",
				number:"Cost price must be a number"
			},
			unit_price:
			{
				required:"Selling Price is a required field",
				number:"Unit price must be a number"
			},
			tax_percent:
			{
				required:"Tax Percent is a required field",
				number:""
			},
			quantity:
			{
				required:"Quantity is a required field. Please Close ( X ) to cancel",
				number:"Quantity must be a number"
			},
			reorder_level:
			{
				required:"Reorder level is a required field",
				number:"Reorder level must be a number"
			}

		}
	});
});
</script>